<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateArticlesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('articles', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string ('title')->default('')->comment('文章标题');
            $table->text ('content')->comment('文章内容');
            $table->unsignedInteger ('user_id')->index()->comment('用户id');
            $table->unsignedInteger ('zan_num')->default(0)->index()->comment('这个文章被点赞的数量');
            $table->unsignedInteger ('favorite_num')->default(0)->index()->comment('这个文章被收藏的数量');
            //外键约束
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('articles');
    }
}
